package com.fick.tags;
/**
 * 显示页面title
 */
import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.fick.common.ContantsProperties;
import com.fick.hibernate.dao.ChannelDAO;
import com.fick.hibernate.dao.NewsDAO;
import com.fick.hibernate.model.Channel;
import com.fick.hibernate.model.News;

@SuppressWarnings("serial")
public class PageTitleCommonTag extends TagSupport {
	private static Log log = LogFactory.getLog(PageTitleCommonTag.class);
	
	//显示自定义内容
	private String show="";
	
	public int doStartTag() throws JspException {
		StringBuffer sb = new StringBuffer();
		HttpServletRequest request = (HttpServletRequest) pageContext
				.getRequest();
		String channelidS = request.getParameter("channelid");
		String newsidS = request.getParameter("newsid");
		String oper = "";
		Channel channel = null;
		News news = null;
		if(!StringUtils.isEmpty(channelidS)){
			channel = new ChannelDAO().findById(Integer.parseInt(channelidS));
		}
		if(!StringUtils.isEmpty(newsidS)){
			news = new NewsDAO().findById(Integer.parseInt(newsidS));
		}
		
		if(channel != null){
			sb.append(channel.getName());
			oper = "-";
		}
		if(news != null){
			sb.append(oper);
			sb.append(news.getTitle());
		}
		if(channel == null && news == null){
			sb.append(ContantsProperties.getContantsProperties().getStringProperty("WEB_SITE_NAME"));
		}
		
			JspWriter out = pageContext.getOut();
			try {
				out.println(sb.toString());
				out.flush();
			} catch (IOException e) {
				log.warn("标签加载错误");
			}
		
		return SKIP_BODY;
	}

	public String getShow() {
		return show;
	}

	public void setShow(String show) {
		this.show = show;
	}

}

